<html>
<head><meta charset="utf-8"><title>do all MIR have a single exit? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/do.20all.20MIR.20have.20a.20single.20exit.3F.html">do all MIR have a single exit?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="204443763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/do%20all%20MIR%20have%20a%20single%20exit%3F/near/204443763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jason Hu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/do.20all.20MIR.20have.20a.20single.20exit.3F.html#204443763">(Jul 20 2020 at 16:24)</a>:</h4>
<p>I am wondering whether MIR code must have a single exit (like the legal ones, not unreachable or friends)? if so, how should I obtain its basic block?</p>



<a name="204444069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/do%20all%20MIR%20have%20a%20single%20exit%3F/near/204444069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/do.20all.20MIR.20have.20a.20single.20exit.3F.html#204444069">(Jul 20 2020 at 16:26)</a>:</h4>
<p>This is not generally a guarantee you can rely on, but it might be true right now</p>



<a name="204444859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/do%20all%20MIR%20have%20a%20single%20exit%3F/near/204444859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/do.20all.20MIR.20have.20a.20single.20exit.3F.html#204444859">(Jul 20 2020 at 16:34)</a>:</h4>
<p>(btw I wonder if these threads should be in <a class="stream" data-stream-id="131828" href="/#narrow/stream/131828-t-compiler">#t-compiler</a>  or <a class="stream" data-stream-id="182449" href="/#narrow/stream/182449-t-compiler.2Fhelp">#t-compiler/help</a>, not entirely sure what <a class="stream" data-stream-id="122651" href="/#narrow/stream/122651-general">#general</a> is for :P)</p>



<a name="204444917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/do%20all%20MIR%20have%20a%20single%20exit%3F/near/204444917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/do.20all.20MIR.20have.20a.20single.20exit.3F.html#204444917">(Jul 20 2020 at 16:35)</a>:</h4>
<p><span class="user-mention" data-user-id="320010">@Jason Hu</span> if you need a SESE region, you need to find all the <code>Return</code>s and if there's more than one, tie them together by rewriting them into <code>Goto</code>s to a block with just a <code>Return</code> in it</p>



<a name="204445068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/do%20all%20MIR%20have%20a%20single%20exit%3F/near/204445068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/do.20all.20MIR.20have.20a.20single.20exit.3F.html#204445068">(Jul 20 2020 at 16:36)</a>:</h4>
<p>although that's the least of your worries if you want structured control-flow, loops can get really bad (a couple years ago we were playing around with some VSDG stuff and that wants structured control-flow. although the input was Cranelift IR not MIR so YMMV)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>